package office.action.sale;

import java.util.List;

import office.action.sale.form.ProductDetailConditionForm;
import office.action.sale.form.ProductDetailForm;
import office.action.sale.form.RivalConditionForm;
import office.action.sale.wrapper.ProductDetailWrapper;
import office.action.sale.wrapper.RivalWrapper;
import office.service.sale.IProductDetailService;
import office.service.sale.IRivalService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;

/**
 * 
 * 产品明细
 * 
 * @author ZhangYQ
 * 
 */
public class ProductDetailAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private IProductDetailService productDetailService;
	private IRivalService rivalService;
	private Page page; // 分页信息
	private List<ProductDetailWrapper> wrapperList;
	private List<RivalWrapper> rivalWrapperList;
	private ProductDetailForm form;
	private ProductDetailConditionForm condition;
	private RivalConditionForm rivalCondition;
	private String id;

	/**
	 * 获取所有的产品明细以及根据条件进行查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findAllProductDetail() throws Exception {
		page = productDetailService.getPageInfo(condition);
		wrapperList = productDetailService.findAllProductDetail(condition,page);
		if(condition!=null){
			return "listProductDetailByPage";
		}
		return "findAllProductDetail";
	}

	/**
	 * 初始化编辑产品明细页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditProductDetail() throws Exception {
		if(null!=id&&!"".equals(id)){
			form = productDetailService.getById(id);
		}
		rivalWrapperList=rivalService.findAllRival(rivalCondition);
		return "gotoEditProductDetail";
	}

	/**
	 * 编辑产品明细
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editProductDetail() throws Exception {
		try {
			productDetailService.editProductDetail(form);
			if (null == form.getId()
					|| ("").equals(form.getId())) {
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询产品结构
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listProductDetailByPage() throws Exception {
		try {
			wrapperList = productDetailService.findAllProductDetail(condition, page);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listProductDetailByPage";
	}

	/**
	 * 初始化产品结构列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoProductDetailMenu() throws Exception {
		return "gotoProductDetailMenu";
	}

	/**
	 * 跳转到产品明细删除确认页面
	 */
	public String gotoDeleteProductDetail(){
		return "gotoDeleteProductDetail";
	}
	
	/**
	 * 删除产品明细
	 * @return
	 * @throws Exception
	 */
	public String delProductDetail() throws Exception {
		try {
			productDetailService.delProductDetailById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}

	public IProductDetailService getProductDetailService() {
		return productDetailService;
	}

	public void setProductDetailService(IProductDetailService productDetailService) {
		this.productDetailService = productDetailService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<ProductDetailWrapper> getWrapperList() {
		return wrapperList;
	}

	public void setWrapperList(List<ProductDetailWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	public ProductDetailForm getForm() {
		return form;
	}

	public void setForm(ProductDetailForm form) {
		this.form = form;
	}

	public ProductDetailConditionForm getCondition() {
		return condition;
	}

	public void setCondition(ProductDetailConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public IRivalService getRivalService() {
		return rivalService;
	}

	public void setRivalService(IRivalService rivalService) {
		this.rivalService = rivalService;
	}

	public List<RivalWrapper> getRivalWrapperList() {
		return rivalWrapperList;
	}

	public void setRivalWrapperList(List<RivalWrapper> rivalWrapperList) {
		this.rivalWrapperList = rivalWrapperList;
	}

	public RivalConditionForm getRivalCondition() {
		return rivalCondition;
	}

	public void setRivalCondition(RivalConditionForm rivalCondition) {
		this.rivalCondition = rivalCondition;
	}
	
}
